#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>

static void worktimeConvert(char *workTime, time_t *timestamp)
{
    int i = 0;
    char *savePtr = NULL, *ptr = NULL;
    struct tm localTime, newTimestamp;
    time_t curTime;
    int hour, minute, second;

    memset(&localTime, 0, sizeof(localTime));
    memset(&newTimestamp, 0, sizeof(newTimestamp));
    hour = minute = second = 0;
    ptr = strtok_r(workTime, ":", &savePtr);
    while (ptr)
    {
        switch(i)
        {
            case 0:
                printf("i:%d,ptr:%s ", i, ptr);
                hour = atoi(ptr);
                break;
            case 1:
                printf("i:%d,ptr:%s ", i, ptr);
                minute = atoi(ptr);
                break;
            case 2:
                printf("i:%d,ptr:%s\n", i, ptr);
                second = atoi(ptr);
                break;
            default:
                printf("i:%d,ptr:%s\n", i, ptr);
                break;
        }
        ptr = strtok_r(NULL, ":", &savePtr);
        ++i;
    }
    printf("[%s:%d] hour:%d,minute:%d,second:%d\n", __func__, __LINE__,hour, minute, second);
    curTime = time(NULL);

    localtime_r(&curTime, &localTime);
    newTimestamp.tm_year = localTime.tm_year;
    newTimestamp.tm_mon = localTime.tm_mon;
    newTimestamp.tm_mday = localTime.tm_mday;
    newTimestamp.tm_hour = hour;
    newTimestamp.tm_min = minute;
    newTimestamp.tm_sec = second;

    *timestamp = mktime(&newTimestamp);

    return;
}

int main(int argc, char *argv[])
{
    char workTime[32] = "20:01";
    time_t timestamp = 0;
    worktimeConvert(workTime, &timestamp);
    printf("timestamp:%lu\n", (unsigned long)timestamp);

    return 0;
}

